package com.xh.hongaicodegenerator.ai;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.xh.hongaicodegenerator.ai.tools.FileWriteTool;
import com.xh.hongaicodegenerator.exception.BusinessException;
import com.xh.hongaicodegenerator.exception.ErrorCode;
import com.xh.hongaicodegenerator.model.enums.CodeGenTypeEnum;
import com.xh.hongaicodegenerator.service.ChatHistoryService;
import com.xh.hongaicodegenerator.utils.SpringContextUtil;
import dev.langchain4j.community.store.memory.chat.redis.RedisChatMemoryStore;
import dev.langchain4j.data.message.ToolExecutionResultMessage;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import dev.langchain4j.model.chat.ChatModel;
import dev.langchain4j.model.chat.StreamingChatModel;
import dev.langchain4j.service.AiServices;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.time.Duration;

@Configuration
@Slf4j
public class AiCodeRoutingTypeServiceFactory {

//    private ChatModel chatModel;

    public AiCodeRoutingTypeService createAiCodeGenTypeRoutingService() {
        ChatModel chatModel = SpringContextUtil.getBean("routingChatModelPrototype", ChatModel.class);
        // 根据 appId 构建独立的对话记忆
        return AiServices.builder(AiCodeRoutingTypeService.class)
                .chatModel(chatModel)
                .build();
    }

    /**
     * 默认提供一个 Bean
     */
    public AiCodeRoutingTypeService aiCodeGenTypeRoutingService() {
        return createAiCodeGenTypeRoutingService();
    }
}
